package com.ssm.juc.theadpool.service;

import com.ssm.juc.theadpool.util.IdFactory;
import com.ssm.juc.theadpool.domain.Order;
import com.ssm.juc.theadpool.dto.OrderDto;
import com.ssm.juc.theadpool.task.OrderTask;
import com.ssm.juc.theadpool.task.OrderTaskManager;
import lombok.extern.slf4j.Slf4j;

/**
 * 订单业务处理
 */
@Slf4j
public class OrderService {

    public String createOrder(OrderDto orderDto) {
        Order order = new Order();
        order.setOrderId(IdFactory.getOrderNum(Long.valueOf(orderDto.getUserId())));

        OrderTask orderTask = new OrderTask(order);
        OrderTaskManager.getInstance().submit(orderTask);
        log.info("订单提交成功, orderId:{}.", order.getOrderId());
        return order.getOrderId();
    }
}
